package main

import (
	"errors"
	"fmt"
	"os"
)

func hello(name string) error{
	if len(name) == 0{
		//自定义错误
		return errors.New("error:name is null")
	}
	return nil
}

func get(index int) (ret int){
	defer func(){
		if r:= recover(); r!= nil{
			fmt.Println("some error happened",r)
			ret = -1
		}
	}()

	arr := [3]int{2,3,4}
	return arr[index]
}

func main()  {
	_,err := os.Open("filename.txt")
	if err != nil{
		fmt.Println(err)
	}

	if err := hello("");err != nil{
		fmt.Println(err)
	}

	fmt.Println(get(5))
}
